$(function () {
    Time();
    load();
})

function fh() {
    localStorage.removeItem("WuLiaoMde");
    location.href = "../../li_meng/GXWLSheJiDan.html";
}

function Time() {
    var time = new Date();
    var y = time.getFullYear();
    var mon = time.getMonth() + 1; //0-11
    var d = time.getDate();
    var h = time.getHours();
    var m = time.getMinutes();
    var s = time.getSeconds();
    $("#date").val(y + "-" + mon + "-" + d + " " + h + ":" + m + ":" + s);
}
let wuXJ = [];
let zong = 0;
function load() {
    let user=JSON.parse(localStorage.getItem("user"))
    $("#rname").val(user.rname);
    let WuLiaoMde=JSON.parse(localStorage.getItem("WuLiaoMde"));

    //工序设计单编号
    $("#designid").text(WuLiaoMde.designid);
    //设计人
    $("#designer").text(WuLiaoMde.designer);
    //产品编号
    $("#productid").text(WuLiaoMde.productid);
    //产品名称
    $("#productname").text(WuLiaoMde.productname);
    //工时总成本
    $("#costpricesum").text(WuLiaoMde.costpricesum);

    //设计要求
    let i=0;
    $("#proceduredescribe").text(WuLiaoMde.proceduredescribe);
    $.post("/Mdesignproceduredetails.do/ChaById", {id:WuLiaoMde.id}, function (sdata) {
        let str = " <tr >\n" +
            "           <th>序号</th>\n" +
            "           <th>工序名称</th>\n" +
            "           <th>工序编号</th>\n" +
            "           <th>描述</th>\n" +
            "           <th>工时数</th>\n" +
            "           <th>工时成本小计(元)</th>\n" +
            "           <th>物料成本小计(元)</th>\n" +
            "           <th>设计</th>\n" +
            "       </tr>\n";

        $.each(sdata, function (index, item) {
            let s = JSON.stringify(item);
            str +="  <tr>\n" +
                "      <td>" + item.detailsnumber + "</td>\n" +
                "      <td>" + item.procedurename + "</td>\n" +
                "      <td>" + item.procedureid + "</td>\n" +
                "      <td>" + item.proceduredescribe + "</td>\n" +
                "      <td>" + item.labourhouramount + "</td>\n" +
                "      <td>"+(item.subtotal==null?'0.00':item.subtotal)+"</td>\n" +
                "      <td>"+(item.modulesubtotal==null?'0.00':item.modulesubtotal)+"</td>\n" +
                "      <td><button class='designmoduletag' onclick='SheJi("+s+")'>"+(item.designmoduletag=='D002-1'?'重新设计':'设计')+
                "</button></td>\n" +
                "  </tr>";
            zong +=item.modulesubtotal==null?0:item.modulesubtotal;
            wuXJ[i]=item.designmoduletag;
            i+=1;
        })
        $("#tableAdd").html(str);
        $("#modulecostpricesum").text(zong);
    })
}

function SheJi(op) {
    localStorage.setItem("MDesignProcedureDetails",JSON.stringify(op));
    location.href="../../li_meng/WuLiaoSheJiDan.html";
}

function Submit() {
    for (let i=0;i<wuXJ.length;i++){
        if (wuXJ[i]=='D002-0'){
            alert("工序物料设计必须全部完成！")
            return;
        }
    }
    let WuLiaoMde=JSON.parse(localStorage.getItem("WuLiaoMde"));
    $.post("/Mdesignprocedure.do/LiMengMdesignprocedureUpdate",{"id":WuLiaoMde.id,
        "modulecostpricesum": $("#modulecostpricesum").text(),
        "designmoduletag":"G002-1","productid":$("#productid").text()},function (sdate) {
        $("#tishi").text("提交成功！")
        $("#tishi").css("color", "lime")
        $("#staticBackdrop").modal("show");
    })
}
function hh() {
    localStorage.removeItem("WuLiaoMde");
    location.href = "../../li_meng/GXWLSheJiDan.html";
}

function xx() {
    location.href = "../../li_meng/GXWuLiaoSheJi(2).html";
}


